<template>
    <div class="root">
       <nav>
            <div @click="goodGoHome()" class="home">  <i style="font-size:5vw;" class="fa fa-angle-left" aria-hidden="true"></i></div>
            <div v-if="goodList.author !=null " v-text="goodList.author.name" class="home" > </div>
            <div @click="addConcern" class="home" v-text="add" id="add"> </div>
        </nav>
        <div class="searchNav">
      <tab class="ctop" active-color="#067c04" v-model="index">
        <tab-item
          class="vux-center"
          :selected="demo2 === item"
          v-for="(item, index) in list"
          @click="demo2 "
          :key="index"
        >{{item}}</tab-item>
      </tab>
      <swiper v-model="index" height="150vw" :show-dots="false">
        <swiper-item class="cNav" v-for="(item, index) in list" :key="index">
          <div v-if="index==0" class="tab-swiper vux-center">
              <homepage> </homepage>
          </div>
          <div v-if="index==1" class="tab-swiper vux-center"><weiju/></div>
          <div v-if="index==2" class="tab-swiper vux-center"></div>
           <div v-if="index==3" class="tab-swiper vux-center"></div>
        </swiper-item>
      </swiper>
    </div>



     <transition v-show="isShowConfirm" name="confirm-fade">
    <div v-if="isShowConfirm" class="my-confirm" @click.stop="clickFun('clickCancel')">
      <div class="confirm-content-wrap" @click.stop>
        <h3 class="my-confirm-title">{{ titleText }}</h3>
        <p class="my-confirm-content">{{ content }}</p>
        <div class="my-operation">
          <div v-if="type==='confirm'" class="my-cancel-btn" @click="clickFun('clickCancel')">
            <p class="my-btn-text my-border-right">{{ cancelText }}</p>
          </div>
          <div class="confirm-btn" @click="clickFun('clickConfirm')">
            <p class="my-btn-text">{{ confirmText }}</p>
          </div>
        </div>
      </div>
    </div>
  </transition>

    </div>
</template>

<script>
import { Confirm,Popup,ConfirmPlugin,Actionsheet } from 'vux'
   import bus from '../../js/bus.js'
   import homepage from './homepage'
   import weiju from './weiju'
import {
  Sticky,
    Divider,
    XButton,
    // Tab,
    // TabItem,Swiper,SwiperItem
} from "vux";
const list = () => ["主页", "微句", "评论", "荣誉"];
export default {
data() {
    return {
        goodList:[],
        list: list(),
        demo2: "",
        index: 0,

        add:"+ 关注",
        // addList:[
        //     {id:1, addConcern:'+ 关注' },
        //     {id:2, addConcerned:'已关注'}
        // ]

        isShowConfirm: false, 
        titleText:'温馨提示',
        content:'确定要取消关注',
        cancelText:'取消',
        confirmText:'确定',
        type:'confirm',
        outerData:null
    }
}, 
components:{
    Sticky,
    Divider,
    XButton,
    homepage,
    weiju,
     Confirm,
       Popup,
       ConfirmPlugin,
       Actionsheet,
} ,   
// props:['goodID'],
 props:['homeMainid'],
 mounted() {
     this.refresh()
    //  var _this = this
    //  bus.$on('goodID', function(data) {
        
    //     _this.ID = data
    //     console.log(_this.ID)
    //  })
 },
 methods: {
    refresh: function() {
        var _this = this
        this.$http.get('/weiju//api/v6/op/authors/'+this.homeMainid +'/sentences?page=1&per_page=20&order_by=hot&token=e16afc7de3b96260de24eb41b22f9879&timestamp=1545440819&app_key=2a438661-92c0-4a2d-b32e-3fd0c47a0a3c&platform=android&channel=ch_xiaomi&version_code=484&version=v3.7.2&system_version=27&device_type=MI%208&device_id=d317466bdcb13faa&signature=85bdfc50c938b04f77760260a0d4b3b7').then(function(data) {
           // console.log(data.body.data)
            _this.goodList = data.body.data[0]
          // console.log(_this.goodList)
            bus.$emit('goodinfo', _this.goodList)
        })
    } ,
    goodGoHome:function() {
        this.$router.push("../")
        $(".weui-tabbar").show();
    },
    addConcern:function() {
        if($('#add').text() == '+ 关注') {
            console.log('aa')
            $("#add").text('已关注')
            $('#add').css('color','gray')
        }else {
             this.isShowConfirm = true
        }
    },

     show(content,config){
        this.content = content || '确定要取消关注'

        if(Object.prototype.toString.call(config) === '[object Object]'){
            this.titleText = config.titleText || '温馨提示'
            this.cancelText = config.cancelText || '取消'
            this.confirmText = config.confirmText || '确定'
            this.type = config.type || 'confirm'
            this.outerData = config.data || null
        }
        this.isShowConfirm = true
    },
    hidden() {

        this.isShowConfirm = false
        this.titleText = '温馨提示'
        this.cancelText = '取消'
        this.confirmText = '确定'
        this.type = 'confirm'
        this.outerData = null
    },
    clickFun (type) {
      this.$emit('userBehavior', type, this.outerData)
      this.hidden()
       $("#add").text('+ 关注')
       $("#add").css('color','white')
    //   window.location.href ='/'
    }



 },
}
</script>

<style scoped>
.root{
    width: 100vw;
    box-sizing: border-box;
    
}
nav{
    width: 100vw;
    display: flex;
    justify-content: space-between;
    background-color: #09bb07;
    height: 15vw;
    line-height: 15vw;
    padding: 0 3vw;
    box-sizing: border-box;
    position: sticky;
    -webkit-position:sticky;
     z-index: 995;
      top: 0vw;
      color: white;
      font-size: 4vw;
}
.rot {
  width: 100vw;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.ctop{
  position: fixed;
  background-color: white;
  width: 100vw;
  z-index: 900;
  font-size: 3.5vw
}
.cNav{
  margin-top: 12vw;
}



.my-confirm {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 998;
    /* 这里防止当用户长按屏幕，出现的黑色背景色块，以及 iPhone 横平时字体的缩放问题 */
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  } /* 进入和出去的动画 */ .confirm-fade-enter-active {
    animation: opacity 0.3s;
  } .confirm-fade-enter-active .confirm-content-wrap {
    animation: scale 0.3s;
  } .confirm-fade-leave-active {
    animation: outOpacity 0.2s;
  } /* 包裹层容器样式 */ .confirm-content-wrap {
    position: absolute;
    top: 28%;
    left: 0;
    right: 0;
    width: 280px;
    margin: 0 auto;
    background-color: #fff;
    border-radius: 5px;
    z-index: 999;
    user-select: none;
  } /* 顶部标题部分 */ .my-confirm-title {
    padding-top: 20px;
    text-align: center;
    font-size: 20px;
    font-weight: 500;
    color: #333;
  } /* 中间内容部分 */ .my-confirm-content {
    padding: 0 15px;
    padding-top: 20px;
    margin-bottom: 32px;
    text-align: center;
    font-size: 16px;
    color: #666;
    line-height: 1.5;
  } /* 底部按钮样式 */ .my-operation {
    display: flex;
    border-top: 1px solid #eee;
  } .my-operation .my-cancel-btn, .confirm-btn {
    flex: 1;
  } .my-operation .confirm-btn {
    color: #ffb000;
  } .my-operation .my-btn-text {
    text-align: center;
    font-size: 16px;
    margin: 14px 0;
    padding: 6px 0;
  } /* 其他修饰样式 */ .my-border-right {
    border-right: 1px solid #eee;
  } /* 进来的动画 */ @keyframes opacity { 0% {
      opacity: 0;
    } 100% {
      opacity: 1;
    } } @keyframes scale { 0% {
      transform: scale(0);
    } 60% {
      transform: scale(1.1);
    } 100% {
      transform: scale(1);
    } } /* 出去的动画 */ @keyframes outOpacity { 0% {
      opacity: 1;
    } 100% {
      opacity: 0;
    } }
</style>
